package gmu.xytxl.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

import gmu.xytxl.bean.Admin;
import gmu.xytxl.dao.ILoginDAO;
import gmu.xytxl.dao.IToJson;
import gmu.xytxl.dao.impl.LoginDAOImpl;
import gmu.xytxl.service.ILoginService;

public class LoginServiceImpl implements ILoginService {
	
	ILoginDAO login = new LoginDAOImpl();
	@Override
	public String loginString(String username, String password) {
		int i = login.findAdmin(username, password);
		//String string = login.result(i);
		
		Map<String, Object> map = new HashMap<String, Object>();
		if (i==1) {
			Admin admin = new Admin();
			admin.setUsername(username);
			map.put("code", 1);
			map.put("msg", "ok");
			Map<String, Object> datamap = new HashMap<String, Object>();
			datamap.put("token","nepadmin-token-test");
			datamap.put("user", admin);
			map.put("data", datamap);
		}else {
			map.put("code", i);
		}
		
		//map.put("data", string);
		JSONObject jsonObject = new JSONObject(map);
		System.out.println("json:"+jsonObject.toString());
		return jsonObject.toString();
		
	}

	

}
